package logic

import (
	"context"

	"shorturl/api/internal/svc"
	"shorturl/api/internal/types"
	"shorturl/rpc/transform/transform"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserListLogic) UserList(req *types.UserListReq) (resp *types.UserListResp, err error) {

	transformRequest := &transform.UserListReq{Page: int64(req.Page)}

	response, err := l.svcCtx.Transformer.UserList(l.ctx, transformRequest)
	if err != nil {
		return nil, err
	}

	var models []types.UserModel
	for _, vlaue := range response.Users {
		models = append(models, types.UserModel{
			ID:             int(vlaue.Id),
			Username:       vlaue.UserName,
			Nickname:       vlaue.Nickname,
			TelphoneNumber: vlaue.TelphoneNumber,
			Email:          vlaue.Email,
			Department:     vlaue.Department,
			Role:           vlaue.Role,
			State:          vlaue.State,
		})
	}

	return &types.UserListResp{

		Content: models,
	}, nil
}
